#ifndef ROOTMENU_H
#define ROOTMENU_H

#include <QMainWindow>
#include <QDialog>
#include <QSql>
#include <QSqlQueryModel>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QString>
#include <QSqlError>
#include <QSqlRecord>

//缺省连接查询语句
#define defaultstr "SELECT s.Name, s.UID, s.Sex, p.Policy, a.Academy, m.Major, s.Grade, s.Class, s.Phone FROM students s INNER JOIN policy p on s.Politics = p.Type INNER JOIN academy a on s.Academy = a.AID INNER JOIN major m on s.Major = m.MID"

namespace Ui {
class RootMenu;
}

class RootMenu : public QMainWindow
{
    Q_OBJECT

public:
    explicit RootMenu(QWidget *parent = nullptr);
    ~RootMenu();

    QSqlDatabase *dbconn;
    void setdbconn(QSqlDatabase *dbconn)
    {
        this->dbconn = dbconn;
    }

    void displayall(QString sqlstr = defaultstr);   //显示条件查询结果
    static QString selectstr(int index, QString cnt);  //返回SQL条件查询语句
    static int searchresult(QString sqlstr);   //返回结果集数据条数

private slots:

    void on_root_add_clicked();

    void on_root_query_clicked();

    void on_root_delete_clicked();

    void on_root_modify_clicked();

private:
    Ui::RootMenu *ui;
    QSqlQueryModel *model;
};

#endif // ROOTMENU_H
